package com.joplus.housekeeper.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.RelativeLayout;

import com.hyphenate.easeui.widget.EaseChatInputMenu;
import com.joplus.housekeeper.R;

/**
 * Created by zisheng on 2017/9/21.
 */

class RabitVpAdapter extends PagerAdapter {
    Context context;
    private final LayoutInflater layout;
    EaseChatInputMenu menu;
    private RabitAdapter rabitAdapter;

    public RabitVpAdapter(EaseChatInputMenu menu) {
        this.context = menu.getContext();
        this.menu = menu;
        layout = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return 2;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = layout.inflate(R.layout.item_chat_gv, null);
        final GridView gridView = (GridView) view.findViewById(R.id.gv);
        rabitAdapter = new RabitAdapter(context, position);
        gridView.setAdapter(rabitAdapter);
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                menu.listener.onGifClick(rabitAdapter.getItem(position));
            }
        });
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        super.destroyItem(container, position, object);
    }
}
